--POUR CONTROLE


define erp='erp_mli2.';
define outils='outils_mli2.';

--CREATE TABLE se_sto_prfcase AS (SELECT * FROM &erp.STO_PRFCASE WHERE 1=2);




DELETE FROM se_sto_prfcase;

 INSERT INTO se_sto_prfcase
 (SELECT id || '_' || typergt prfcase_cod,
         typergt prfcontrainte_cod,
         0 enreg_id,
         libelle prfcase_lib,
         NULL prfcase_lib2,
         'N' enreg_s,
         'O' monoprod_ok,
         1 emplacement_typ
    FROM uv_ptypecases) ;

 UPDATE se_sto_prfcase tf SET enreg_id=(select enreg_id FROM &erp.STO_PRFCASE f WHERE f.PRFCASE_COD=tf.PRFCASE_COD) ;
 UPDATE se_sto_prfcase tf SET enreg_id=&outils.enreg_id.NEXTVAL WHERE enreg_id IS NULL OR enreg_id =0;



 CALL uvse_synchroverserp('PRFCASE_COD','STO_PRFCASE','O') ;

 commit;



select * from (
SELECT &outils.stragg(source) source,prfcase_cod, prfcontrainte_cod, enreg_id, prfcase_lib, prfcase_lib2, enreg_s, monoprod_ok, emplacement_typ
FROM (
  SELECT 'uv' source ,g.* FROM se_sto_prfcase g
  UNION ALL
  SELECT 'se' source ,g.* FROM &erp.sto_prfcase g
  )
GROUP BY prfcase_cod, prfcontrainte_cod, enreg_id, prfcase_lib, prfcase_lib2, enreg_s, monoprod_ok, emplacement_typ
HAVING Count(1)!=2) r
ORDER BY prfcase_cod;